package com.tanhua.server.controller;


import com.tanhua.model.vo.PageResult;
import com.tanhua.server.service.CommnetsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequestMapping("/comments")
@RestController
public class CommentsController {
    @Autowired
    private CommnetsService commnetsService;

    /**
     *发布评论
     */
    @PostMapping
    public ResponseEntity saveComments(@RequestBody Map map){
        String movenmentId = (String)map.get("movementId");
        String comment = (String)map.get("comment");
        commnetsService.saveComments(movenmentId,comment);
        return ResponseEntity.ok(null);
    }

    /**
     * 分页查询评论列表
     */
    @GetMapping
    public ResponseEntity findComments(@RequestParam(defaultValue = "1") Integer page,
                                    @RequestParam(defaultValue = "10") Integer pagesize,
                                       String movementId) {
        PageResult pr = commnetsService.findComments(movementId,page, pagesize);
        return ResponseEntity.ok(pr);
    }
}
